import { onMounted, onUnmounted,ref } from "vue"


const getMouseLocation = () => {
  // 自定义hook
  // 需求: 获取鼠标实时位置,要求在其他页面也要用
  const pageX = ref(0)
  const pageY = ref(0)

  const mouseMoveHandler = (e) => {
    let { pageX: x, pageY: y } = e

    pageX.value = x
    pageY.value = y
  }

  onMounted(() => {
    document.addEventListener('mousemove', mouseMoveHandler)
  })

  onUnmounted(() => {
    document.removeEventListener('mousemove', mouseMoveHandler)
  })

  return {
    pageX,
    pageY,
  }
}


export default getMouseLocation